// 登录框显示与隐藏
document.querySelector('header div.member div').onclick=function(){
    document.querySelector('section.login').style.visibility='visible'
}
document.querySelector('section.login .item .icon-close').onclick=function(){
    document.querySelector('section.login').style.visibility='hidden'
    mobileobj.value=''
    passwordobj.value=''
    document.querySelector('section.login .item p:nth-of-type(3)').innerText=''
    document.querySelector('section.login .item p:nth-of-type(4)').innerText=''
}



// // 登录框拖拽
let blueObj=document.querySelector('section.login .menu')
blueObj.onmousedown=function(evt){
    let oldE= evt || window.event
    document.onmousemove=function(evt){
        let e = evt || window.event
        let itemObj=document.querySelector('section.login .item')
        let left=e.clientX-oldE.offsetX
        let top=e.clientY-oldE.offsetY
        if(left<0){
            left=0
        }
        if(top<0){
            top=0
        }
        let maxLeft=(window.innerWidth||document.documentElement.clientWidth)-itemObj.offsetWidth
        let maxtop=(window.innerHeight||document.documentElement.clientHeight)-itemObj.offsetHeight
        if(left>maxLeft){
            left=maxLeft
        }
        if(top>maxtop){
            top=maxtop
        }
        itemObj.style.position='absolute'
        itemObj.style.left=left+'px'
        itemObj.style.top=top+'px'
    }
    document.onmouseup=function(){
        document.onmousemove=null
    }
}

//行为验证码+发送与验证码倒计时
let yzmNum=60
let yzBtn=document.querySelector('section.login .item .captcha')
yzBtn.onclick=function(){
    document.querySelector('section.captcha').style.visibility='visible'
}
document.querySelector('section.captcha .icon-close').onclick=function(){
    document.querySelector('section.captcha').style.visibility='hidden'
}
let captchaBtn=document.querySelector('section.captcha .drag .btn')
captchaBtn.onmousedown=function(){
    document.onmousemove=function(evt){
        let e=evt||window.event
        let captchaObj=document.querySelector('section.captcha')
        let dragBtn=document.querySelector('section.captcha .drag')
        let imgBtn=document.querySelector('section.captcha img:nth-of-type(2)')
        let left=e.clientX-captchaObj.offsetLeft+captchaObj.offsetWidth/2-dragBtn.offsetLeft-captchaBtn.offsetWidth/2
        if(left<0){
            left=0
        }
        let maxLeft=dragBtn.offsetWidth-captchaBtn.offsetWidth
        if(left>maxLeft){
            left=maxLeft
        }
        captchaBtn.style.left=left+'px'
        imgBtn.style.left=left+'px'
    }
    document.onmouseup=function(){
        document.onmousemove=null
        let result=parseInt(captchaBtn.style.left)
        if(result>=260&&result<=265){
            document.querySelector('section.captcha').style.visibility='hidden'
            yzBtn.innerText=`${yzmNum}秒后重发`
            yzBtn.disabled=true
            yzt=setInterval(() => {
                yzmNum--
                if(yzmNum<=0){
                    clearInterval(yzt)
                    yzBtn.innerText='重新发送'
                    yzmNum=60
                    yzBtn.disabled=false
                    return
                }
                yzBtn.innerText=`${yzmNum}秒后重发`
            },1000);
        }
        captchaBtn.style.left=0
        document.querySelector('section.captcha img:nth-of-type(2)').style.left=0
    }
}

// 表单验证提交
// let subBtnNum1=0
// let subBtnNum2=0
// let mobileobj=document.querySelector('section.login .item .mobile')
// mobileobj.onfocus=function(){
//     document.querySelector('section.login .item p:nth-of-type(3)').innerText=''
// }
// mobileobj.onblur=function(){
//     subBtnNum1=0
//     if(/^1\d{10}$/.test(mobileobj.value)){
//         subBtnNum1++
//         document.querySelector('section.login .item p:nth-of-type(3)').innerText=''
//     }else{
//         document.querySelector('section.login .item p:nth-of-type(3)').innerText='请输入正确的手机号'
//     }
// }
// let passwordobj=document.querySelector('section.login .item .password')
// passwordobj.onfocus=function(){
//     document.querySelector('section.login .item p:nth-of-type(5)').innerText=''
// }
// passwordobj.onblur=function(){
//     subBtnNum2=0
//     if(/^\d{4}$/.test(passwordobj.value)){
//         subBtnNum2++
//         document.querySelector('section.login .item p:nth-of-type(5)').innerText=''
//     }else{
//         document.querySelector('section.login .item p:nth-of-type(5)').innerText='请输入正确的验证码'
//     }
// }